package com.example.ordersystem.dao;


import com.example.ordersystem.domain.Lineitem;
import com.example.ordersystem.domain.LineitemInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface LineitemDAOByMybatis {

    /**
     * 插入一个订单明细记录
     * @param lineitem 待插入的订单明细
     * @return 自增的主键值
     */
    @Insert("INSERT INTO lineitem(orderNum,dishNum,dishPrice,quantity,amount) VALUES" +
            " (#{orderNum}, #{dishNum},#{dishPrice},#{quantity},#{amount})")
    @Options(useGeneratedKeys = true, keyProperty = "num", keyColumn = "num")
    int addLineitem(Lineitem lineitem);


    /**
     * 根据订单编号查询各个订单项
     * @param orderNum 订单编号
     * @return 各个订单项
     */
    @Select("select * from lineiteminfo where orderNum=#{orderNum}")
    List<LineitemInfo> selectByOrderNum(@Param("orderNum") String orderNum);
}
